<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Cms extends MX_Controller {
    
  function __construct() {
//    $this->load->library('manimage');
    $this->load->model('frm/mfrm');
    $this->menu = $this->cek();
  }
  
  function setting_cms(){
    if($this->input->post(NULL)){
      $pst = $this->input->post(NULL);
//      $keuangan_mahasiswa_setting_cms_group = $this->nbscache->get_explode("variable", "keuangan_mahasiswa_setting_cms_group");
//      $this->debug(unserialize($keuangan_mahasiswa_setting_cms_group[1]));
//      $this->debug($pst, true);
      $data_zip = array(
          "keuangan_mahasiswa_setting_cms_group_admin"      => $pst['keuangan_mahasiswa_setting_cms_group_admin'],
          "keuangan_mahasiswa_setting_cms_group_keuangan"   => $pst['keuangan_mahasiswa_setting_cms_group_keuangan'],
          "keuangan_mahasiswa_setting_cms_mahasiswa"        => $pst['keuangan_mahasiswa_setting_cms_mahasiswa'],
          "keuangan_mahasiswa_setting_cms_purchase"         => $pst['keuangan_mahasiswa_setting_cms_purchase']
      );
      $this->nbscache->put_tunggal("variable", "keuangan_mahasiswa_setting_cms_group", serialize($data_zip));
      $this->nbscache->put_tunggal("variable", "keuangan_mahasiswa_setting_cms_group_keuangan2", $pst['keuangan_mahasiswa_setting_cms_group_keuangan2']);
      
      $this->nbscache->put_tunggal("variable", "keuangan_mahasiswa_setting_cms_group_admin2", $pst['keuangan_mahasiswa_setting_cms_group_admin2']);
      
//      $this->nbscache->put_tunggal("variable", "keuangan_mahasiswa_setting_cms_mahasiswa", $pst['keuangan_mahasiswa_setting_cms_mahasiswa']);
      $this->nbscache->put_tunggal("variable", "keuangan_mahasiswa_setting_cms_mahasiswa2", $pst['keuangan_mahasiswa_setting_cms_mahasiswa2']);
      
//      $this->nbscache->put_tunggal("variable", "keuangan_mahasiswa_setting_cms_purchase", $pst['keuangan_mahasiswa_setting_cms_purchase']);
      $this->nbscache->put_tunggal("variable", "keuangan_mahasiswa_setting_cms_purchase2", $pst['keuangan_mahasiswa_setting_cms_purchase2']);
    }
//    else{
    
    $keuangan_mahasiswa_setting_cms_group = $this->nbscache->get_explode("variable", "keuangan_mahasiswa_setting_cms_group");
//    $keuangan_mahasiswa_setting_cms_group_keuangan = $this->nbscache->get_explode("variable", "keuangan_mahasiswa_setting_cms_group_keuangan");
//    $keuangan_mahasiswa_setting_cms_mahasiswa = $this->nbscache->get_explode("variable", "keuangan_mahasiswa_setting_cms_mahasiswa");
//    $keuangan_mahasiswa_setting_cms_purchase = $this->nbscache->get_explode("variable", "keuangan_mahasiswa_setting_cms_purchase");
    
    $this->global_models->get_connect("zikula");
    foreach (unserialize($keuangan_mahasiswa_setting_cms_group[1]) AS $key => $value){
      $data[$key] = $this->global_models->get_field("academicportal_groups", "pn_name", array("pn_gid" => $value));
    }
    
    
//    $data['keuangan_mahasiswa_setting_cms_mahasiswa'] = $this->global_models->get_field("academicportal_groups", "pn_name", 
//            array("pn_gid" => $keuangan_mahasiswa_setting_cms_mahasiswa[1]));
//    
//    $data['keuangan_mahasiswa_setting_cms_purchase'] = $this->global_models->get_field("academicportal_groups", "pn_name", 
//            array("pn_gid" => $keuangan_mahasiswa_setting_cms_purchase[1]));
    $this->global_models->get_connect("default");
    
    $this->template->build("cms/setting-cms",
      array(
            'url'         => base_url()."themes/".DEFAULTTHEMES."/",
            'menu'        => 'keuangan-mahasiswa/cms/setting-cms',
            'title'       => lang("settings"),
            'data'        => $data,
            'data_value'  => unserialize($keuangan_mahasiswa_setting_cms_group[1]),
          ));
    $this->template
      ->set_layout('default')
      ->build("cms/setting-cms");
  }
  
  function auto_group_users(){
    if (empty($_GET['term'])) exit ;
    $q = strtolower($_GET["term"]);
    if (get_magic_quotes_gpc()) $q = stripslashes($q);
    $this->global_models->get_connect("zikula");
    $items = $this->global_models->get_query("
      SELECT *
      FROM academicportal_groups
      WHERE
      LOWER(pn_name) LIKE '%{$q}%'
      LIMIT 0,10
      ");
    $this->global_models->get_connect("default");
    if(count($items) > 0){
      foreach($items as $tms){
        $result[] = array(
            "id"    => $tms->pn_gid,
            "label" => $tms->pn_name,
            "value" => $tms->pn_name,
        );
      }
    }
    else{
      $result[] = array(
          "id"    => 0,
          "label" => "No Found",
          "value" => "No Found",
      );
    }
    echo json_encode($result);
    die;
  }
  
  function auto_group_users2(){
    if (empty($_GET['term'])) exit ;
    $q = strtolower($_GET["term"]);
    if (get_magic_quotes_gpc()) $q = stripslashes($q);
//    $this->global_models->get_connect("zikula");
    $items = $this->global_models->get_query("
      SELECT *
      FROM m_privilege
      WHERE
      parent > 0 AND
      LOWER(name) LIKE '%{$q}%'
      LIMIT 0,10
      ");
//    $this->global_models->get_connect("default");
    if(count($items) > 0){
      foreach($items as $tms){
        $result[] = array(
            "id"    => $tms->id_privilege,
            "label" => $tms->name,
            "value" => $tms->name,
        );
      }
    }
    else{
      $result[] = array(
          "id"    => 0,
          "label" => "No Found",
          "value" => "No Found",
      );
    }
    echo json_encode($result);
    die;
  }
  
  function jenis_virtual_account(){
    $data = $this->global_models->get_query("
      SELECT A.*
      FROM keuangan_mahasiswa_jenis_virtual_account AS A
      ");
    $this->template->build("cms/jenis-virtual-account",
      array(
            'url'         => base_url()."themes/".DEFAULTTHEMES."/",
            'menu'        => 'keuangan-mahasiswa/cms/jenis-virtual-account',
            'title'       => lang("keuangan_mahasiswa_jenis_virtual_account"),
            'data'        => $data,
          ));
    $this->template
      ->set_layout('default')
      ->build("cms/jenis-virtual-account");
  }
  
  function add_jenis_virtual_account($id_keuangan_mahasiswa_jenis_virtual_account = 0){
    if($this->input->post()){
      $pst = $this->input->post();
      if($pst['id_detail']){
        $kirim = array(
            "code"                  => $pst['code'],
            "title"                 => $pst['title'],
            "update_by_users"       => $this->session->userdata("id"),
        );
        $id_keuangan_mahasiswa_jenis_virtual_account = $this->global_models->update("keuangan_mahasiswa_jenis_virtual_account", 
                array("id_keuangan_mahasiswa_jenis_virtual_account" => $pst['id_detail']), $kirim);
      }
      else{
        $kirim = array(
            "code"                  => $pst['code'],
            "title"                 => $pst['title'],
            "create_by_users"       => $this->session->userdata("id"),
            "create_date"           => date("Y-m-d H:i:s")
        );
        $id_keuangan_mahasiswa_jenis_virtual_account = $this->global_models->insert("keuangan_mahasiswa_jenis_virtual_account", $kirim);
      }
      if($id_keuangan_mahasiswa_jenis_virtual_account){
        $this->session->set_flashdata('success', 'Data tersimpan');
      }
      else{
        $this->session->set_flashdata('notice', 'Data tidak tersimpan');
      }
      
      redirect("keuangan-mahasiswa/cms/jenis-virtual-account");
    }
    else{
      $data = $this->global_models->get("keuangan_mahasiswa_jenis_virtual_account", array("id_keuangan_mahasiswa_jenis_virtual_account" => $id_keuangan_mahasiswa_jenis_virtual_account));
      $this->template->build("cms/add-jenis-virtual-account",
        array(
              'url'         => base_url()."themes/".DEFAULTTHEMES."/",
              'menu'        => 'keuangan-mahasiswa/cms/jenis-virtual-account',
              'title'       => lang("keuangan_mahasiswa_jenis_virtual_account"),
              'detail'      => $data,
            ));
      $this->template
        ->set_layout('default')
        ->build("cms/add-jenis-virtual-account");
    }
  }
  
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */